import unittest
from discretemath import *

class CombPermTestCase(unittest.TestCase):

    def testCombination(self):
        combs = [c for c in combination(range(10),3)]
        self.assertEqual(len(combs),combination_num(10,3))
        self.assertEqual(len([c for c in combination(range(8),8)]),1)
        

    def testCombination_num(self):
        c = combination_num(8,3)
        self.assertEqual(c,56)
        c = combination_num(1,1)
        self.assertEqual(c,1)

    def testPermutation(self):
        perms = [p for p in permutation(range(5),4)]
        self.assertEqual(len(perms),permutation_num(5,4))
        self.assertEqual([p for p in permutation(range(8),1)][0],
                         [7])

    def testPermutation_num(self):
        p = permutation_num(8,3)
        self.assertEqual(p,8*7*6)
        p = permutation_num(11,1)
        self.assertEqual(p,11)
                         

if __name__ == "__main__":unittest.main()
